/*-*
 * FILENAME  :
 *    $HeadURL$
 *
 * STATUS  :
 *    $Revision$
 *
 *    $Author$
 *    $Date$
 *  
 *    
 * Copyright (c) 2011 Gonalge Ltda. All rights reserved.
 *
 ****************************************************************/

package org.gonalge.rompecabeza.util;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * @author Geremias Gonzalez
 */
public class FormUtils {

    private static final Log LOG = LogFactory.getLog(FormUtils.class);

    public static Rectangle centarRectangle(int widthForm, int heightForm) {
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (dim.width - widthForm) / 2;
        int y = (dim.height - heightForm) / 2;
        return new Rectangle(x, y, widthForm, heightForm);
    }

    public static BufferedImage getImagen(Class<?> contenedor, String name) {
        try {
            return ImageIO.read(contenedor.getClassLoader().getResource("img/" + name + ".gif"));
        } catch (Exception e) {
            LOG.error("Error de imagen: " + name, e);
            return null;
        }
    }

    public static ImageIcon getImageIcon(Class<?> contenedor, String name) {
        return new ImageIcon(getImagen(contenedor, name));
    }

    public static Color getColorFondo() {
        return new Color(179, 207, 252);
    }

    public static Color getColorTitulo() {
        return new Color(185, 0, 0);
    }
}
